/*
 * @Author: weikang
 * @Description:
 * @Date: 2024-02-20 21:56:10
 * @LastEditTime: 2024-04-02 09:07:46
 * @FilePath: \env-manager-pc\src\views\document\manager\create\access\page.ts
 */
import { AccountType } from '@/api/modules/types/user'

export function useRules(AffiliatedObjType: string) {
  return computed(() => ({
    AccountCode: {
      required: true,
      message: '请输入账号',
      trigger: 'blur',
    },
    Name: {
      required: true,
      message: '请输入姓名',
      trigger: 'blur',
    },
    Roles: {
      required: true,
      message: '请选择角色',
      trigger: 'blur',
    },
    StateID: {
      required: true,
      message: '请选择状态',
      trigger: 'blur',
    },
    AffiliatedObjID: {
      required: AffiliatedObjType !== AccountType.Enterpris,
      message: '请选择隶属机构',
      trigger: 'blur',
    },

  }))
}

export interface AccountForm {
  AccountObjID: string
  AccountCode: string
  Name: string
  AffiliatedObjType: string
  AffiliatedObjID: string
  AffiliatedObjName: string
  StateID: number
  Roles: string[]
  StateRemark: string
  ExpirTime: string | null
  ContactTel: string
  MsgTel: string
  WxOpenID: string
  LogonTime: string
}

export function useInitForm(userInfo: any): { formData: Ref<AccountForm>, initForm: () => void } {
  const getData = (): AccountForm => ({
    AccountObjID: '',
    AccountCode: '',
    Name: '',
    AffiliatedObjType: 'Enterprise',
    AffiliatedObjID: userInfo.ObjID,
    AffiliatedObjName: '',
    StateID: 1,
    StateRemark: '',
    ExpirTime: '',
    ContactTel: '',
    MsgTel: '',
    WxOpenID: '',
    LogonTime: '',
    Roles: [],
  })
  const formData = ref<AccountForm>(getData())

  const initForm = () => {
    formData.value = getData()
  }

  return { formData, initForm }
}
